package com.zpark.cloud.alibaba.feign.impl;

import com.zpark.cloud.alibaba.feign.IAccountFeign;
import com.zpark.cloud.alibaba.utils.ResponseResult;
import io.seata.core.context.RootContext;
import io.seata.core.exception.TransactionException;
import io.seata.tm.api.GlobalTransactionContext;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * @PackageName: com.zpark.cloud.alibaba.feign.impl
 * @ClassName: AccountFeignImpl
 * @Description:
 * @author: RZS
 * @date: 2023/6/28  16:44
 */
@Component
public class AccountFeignImpl implements IAccountFeign {
    @Override
    public ResponseResult<Void> changeAccountResidue(Long uid, BigDecimal money) {
        //手动回滚
        try {
            GlobalTransactionContext.reload(RootContext.getXID()).rollback();
        } catch (TransactionException e) {
            e.printStackTrace();
        }
        return new ResponseResult<>(500, "在订单微服务中使用Feign远程调用seata-account出错", null);
    }
}
